package com.wyg.service;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wyg.dao.UserDao;
import com.wyg.pojo.User;

public class RegisteService {
	
	public HttpServletRequest request;
	public HttpServletResponse response;
	public UserDao ud = new UserDao();
	
	public RegisteService(HttpServletRequest request, HttpServletResponse response) {
		super();
		this.request = request;
		this.response = response;
	}
	
	public void registe(){
		User user = new User(request.getParameter("phone"),request.getParameter("pwd"),request.getParameter("name"),
				request.getParameter("ip"),request.getParameter("address"),request.getParameter("abc"),"未激活");
		ud.registe(user);
		try {
			response.sendRedirect("view/success.html");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	//手机号验证
	public void phone() throws IOException{
		String phone = request.getParameter("method");
		User user = ud.queryPhone(phone);
		if(user!=null){
			System.out.println("user!=null");
			PrintWriter out = response.getWriter();
			out.print("<font style='color:#F00'>该手机号已被注册</font>");
			out.close();
		}else{
			PrintWriter out=response.getWriter();
			out.print("<font style='color:green'>该手机号可用</font>");
			out.close();
		}
	}

}
